import java.util.ArrayList;

/**
 * Created by forcht on 2018/4/28.
 */
public class Solution {
    public int minimumTotal(ArrayList<ArrayList<Integer>> triangle) {
        int row=triangle.size();
        ArrayList<Integer> integers = triangle.get(row-1);
        int columns=integers.size();
        int[] dp=new int[columns];
        for(int i=0;i<integers.size();i++){
            dp[i]=integers.get(i);
        }
        for(int i=row-2;i>=0;i--){
            integers=triangle.get(i);
            columns=integers.size();
            for(int j=0;j<columns;j++){
                dp[j]=Math.min(dp[j],dp[j+1])+integers.get(j);
            }
        }
        return dp[0];
    }
}
